using System;
using System.Collections.Generic;
using System.Text;

namespace Blimpbots.Recognition.Algorithms
{
    public class ShuffledList<T> : List<T>
    {
        /// <summary>
        /// Removes an element by swapping the end with it, and then
        /// popping the element off of the list.  Guaranteed O(1)
        /// </summary>
        /// <param name="index">Index of item to be removed</param>
        public void RemoveAtSwap(int index)
        {
            // Swap the end into the desired index to remove
            this[index] = this[this.Count - 1];
            // Remove the end -- O(1)
            this.RemoveAt(this.Count - 1);
        }
        
        public ShuffledList(IEnumerable<T> col)
        {
            base.AddRange(col);
        }

        public void Shuffle(int times)
        {

            Random r = new Random();
            int idx;
            for (int t = 0; t < times; t++)
            {
                for (int i = 0; i < this.Count; i++)
                {
                    /* Swap items */
                    idx = r.Next(this.Count);
                    T temp = this[i];
                    this[i] = this[idx];
                    this[idx] = temp;
                }
            }
        }
    }
}
